// http.ts
import axios from 'axios';

// 创建一个 Axios 实例
const instance = axios.create({
    baseURL: '/api',  // 设置基础请求路径
    timeout: 30000,   // 设置请求超时时间
});

// 请求拦截器（可选，根据需要）
instance.interceptors.request.use(
    (config) => {
        // 可以在这里添加请求头或其他配置
        return config;
    },
    (error) => {
        return Promise.reject(error);
    }
);

// 响应拦截器（可选，根据需要）
instance.interceptors.response.use(
    (response) => {
        // 处理响应数据
        return response.data;
    },
    (error) => {
        return Promise.reject(error);
    }
);


export function loadCities() {
    return instance.get('/cities');
}

export function loadAttributes(cityName: string) {
    return instance.get('/attributes?city_name=' + cityName);
}

export function getHistoryData(cityName: string, attribute: string) {
    return instance.get('/history?city_name=' + cityName + '&attribute=' + attribute);
}

export function predict(cityName: string, attribute: string, steps: number) {
    return instance.post('/predict', {
        city_name: cityName,
        attribute: attribute,
        steps: steps,
    });
}


export function getRecommend(cityName: string, age: string, gender: string, targetDate: string) {
    return instance.post('/recommend', {
        city_name: cityName,
        age,
        gender,
        target_date: targetDate,
    }, {
        timeout: 100000,
    })
}

export function getRecommendImage(r: object) {
    return instance.post('/recommend_images', r)
}
